<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>我的地址</title>
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1,user-scalable=no" />
		<meta name="format-detection" content="telephone=no" />
		<meta content="true" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/page.css" />
		<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
	</head>

	<body class="bg1">
		<div class="address">
			<div class="row flex">
				<label>收件人</label>
				<input type="text" class="flex-1" placeholder="真实姓名" id="name" />
			</div>
			<div class="row flex">
				<label>手机号</label>
				<input type="text" class="flex-1" placeholder="" id="phone" />
			</div>
			<div class="row flex arrow">
				<label>所在地</label>
				<span class="select flex-1 text-right" id="addr">请选择<span>
			<!--	<input type="text" name="" id="citylist" value="" placeholder='请选择' class="select flex-1 text-right" readonly="readonly" />
				<input id="value2" type="hidden" />-->

			</div>
			<div class="row flex">
				<textarea class="flex-1" placeholder="详细地址" id="address"></textarea>
			</div>
			<div>
			</div>
		</div>
		<div class="opbtn text-center flex " style="margin-top:50px; margin-left: 15px; margin-right: 15px;">
			<button class="btn save flex-1">提交</button>
		</div>
	</body>

</html>

<script src="js/jweixin-1.0.0.js"></script>
<script src="js/jquery-3.1.1.js" type="text/javascript" charset="utf-8"></script>
<script src="https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/2.5.1/vconsole.min.js"></script>
<script src="js/md5.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.eraser.js" type="text/javascript" charset="utf-8"></script>
<script src="js/index.js?v=16" type="text/javascript" charset="utf-8"></script>
<script src="js/mui.min.js"></script>
<script src="js/mui.poppicker.js"></script>
<script src="js/mui.picker.min.js"></script>
<script src="js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
	[data-type=date] .mui-dtpicker-title h5,
	[data-type=date] .mui-picker {
		width: 33.3%;
		box-sizing: border-box;
	}
	
	.mui-dtpicker-header button,
	.mui-poppicker-header .mui-btn {
		font-size: 14px;
		padding: 5px 10px;
		border: none;
		color: #ec723c;
		background: none;
		font-family: "微软雅黑"
	}
	
	.mui-dtpicker-header button:active,
	.mui-poppicker-header .mui-btn:active {
		font-size: 14px;
		padding: 5px 10px;
		border: none !important;
		color: #ec723c!important;
		background: none !important;
	}
	
	.mui-toast-container {
		top: 20%;
		z-index: 999999;
	}
	
	.mui-toast-message {
		background: rgba(0, 0, 0, 0.5);
		color: #fff;
	}
</style>
<script>
	(function(mui, doc) {
			var cityPicker3 = new mui.PopPicker({
				layer: 3
			});
			cityPicker3.setData(cityData);
			var showCityPickerButton = doc.getElementById('addr');
			var showCityPicker3 = doc.getElementById('addr');
			showCityPickerButton.addEventListener('click', function(event) {
						cityPicker3.show(function(items) {
									showCityPicker3.innerHTML = (items[0].text || '') + " " + (items[1].text || '') + " " + (items[2].text || '');
									//返回 false 可以阻止选择框的关闭 
									//return false;
									}); }, false); })(mui, document);
</script>
<script>
	$(function() {
		_getOpenid(function(res) {
			/*查询是否有地址信息*/
			queryEntityPrize(Openid, function(data) {
				if(parseInt(data.code) == 200 && data.data.length > 0) {
					var data = data.data[0];
					if(data.address) {
						$('#address').val(decodeURI(data.address));

					}
					$('#phone').val(data.mobile);
					$('#name').val(data.name);
					$('#addr').text(data.address_code)

				} else {
					console.log(data.msg);
				}
			});
			/*分享*/
			getWxJsApi(false);
		})

		$('.save').click(function() {

			var address = $('#address').val();
			var mobile = $('#phone').val();
			var rgx = /^1\d{10}$/;
			if(!rgx.test(mobile)) {
				//showMessage('请输入正确的手机号码');
				$('body').toast({fontSize:'14px',content:'请输入正确的手机号码'});
				return false;
			}
			var name = $('#name').val();
			var reg2= /^[\w\u4e00-\u9fa5]+$/gi;
			if(!reg2.test(name)) {
				//showMessage('请输入正确的手机号码');
				$('body').toast({fontSize:'14px',content:'请输入正确的姓名'});
				return false;
			}
			var address_code = $('#addr').text();
			if(!address || !mobile || !name || !address_code) {
				//showMessage('请完善地址信息');
				$('body').toast({fontSize:'14px',content:'请完善地址信息'});
				return false;
			};

			updateEntityPrizeUser(encodeURI(address), mobile, encodeURI(name), Openid, encodeURI(address_code), function() {
				//showMessage('保存成功');
				$('body').toast({fontSize:'14px',content:'保存成功'});
				setTimeout(function() {
					window.location.href = "award.html?channel=entity";
				}, 1500)
			})
		})
	})
</script>